package gui.controlpanel;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Group;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JPanel;

import client.controlpanel.AboutButton;
import client.controlpanel.SettingsButton;
import client.controlpanel.StartGatheringButton;
import client.controlpanel.StopGatheringButton;

import gui.Element;

public class ControlPanelElement implements Element {
	JPanel controlPanel;

	JButton startButton;
	JButton stopButton;
	JButton settingButton;
	JButton aboutButton;

	@Override
	public void init() {
		controlPanel = new JPanel();

		startButton = new JButton();
		startButton.setText("Start gathering data");
		
		stopButton = new JButton();
		stopButton.setText("Stop gathering data");
		stopButton.setEnabled(false);
		
		startButton.addActionListener(new StartGatheringButton(stopButton));
		stopButton.addActionListener(new StopGatheringButton(startButton));
		
		settingButton = new JButton();
		settingButton.setText("Settings...");
		settingButton.addActionListener(new SettingsButton(startButton, stopButton));
		
		aboutButton = new JButton();
		aboutButton.setText("About...");
		aboutButton.addActionListener(new AboutButton());
		
		GroupLayout layout = new GroupLayout(controlPanel);

		Group horizontalGroup = layout.createSequentialGroup();
		layout.setHorizontalGroup(horizontalGroup);
		horizontalGroup.addGroup(layout.createParallelGroup(GroupLayout.Alignment.CENTER).addComponent(
				startButton).addComponent(settingButton));
		horizontalGroup.addGroup(layout.createParallelGroup(GroupLayout.Alignment.CENTER).addComponent(
				stopButton).addComponent(aboutButton));

		Group verticalGroup = layout.createSequentialGroup();
		layout.setVerticalGroup(verticalGroup);
		verticalGroup.addGroup(layout.createParallelGroup().addComponent(startButton).addComponent(stopButton));
		verticalGroup.addGroup(layout.createParallelGroup().addComponent(settingButton).addComponent(aboutButton));
		
		layout.setAutoCreateGaps(true);
		layout.setAutoCreateContainerGaps(true);
		
		controlPanel.setLayout(layout);
	}

	@Override
	public JComponent getComponent() {
		return controlPanel;
	}

	@Override
	public String getCaption() {
		return "";
	}

	@Override
	public boolean isLeftPanel() {
		return true;
	}

}
